import { getBookingScheduleRule } from '../../api/index';

export const _toggleListLoading = (payload) => {
  return {
    type: 'TOGGLE_LIST_LOADING',
    payload,
  };
};

export const _getScheduleListDataInfoData = (payload) => {
  return {
    type: 'GET_SCHEDULE_LISTDATA_INFO',
    payload,
  };
};

export function getScheduleListDataInfo({ page, limit, hoscode, depcode }) {
  return async (dispatch) => {
    try {
      await dispatch(_toggleListLoading(true));
      const listResult = await getBookingScheduleRule(
        page,
        limit,
        hoscode,
        depcode
      );
      const listDataObj = {
        list: listResult.bookingScheduleList,
        baseMap: listResult.baseMap,
        total: listResult.total,
      };

      await dispatch(_getScheduleListDataInfoData(listDataObj));
      await dispatch(_toggleListLoading(false));
    } catch (error) {
      await dispatch(_toggleListLoading(false));
      // console.log(error);
    }
  };
}
